<template>
  <div class="app-container">
    <el-form class="formWidth"  :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="民族" prop="nationality">
        <el-input
          v-model="queryParams.nationality"
          placeholder="请输入民族"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出生日期" prop="birthDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.birthDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择出生日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="身份证号" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入身份证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入伍时间" prop="enterArmyTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.enterArmyTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择入伍时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="退伍时间" prop="veteransTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.veteransTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择退伍时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="联系电话" prop="phoneNo">
        <el-input
          v-model="queryParams.phoneNo"
          placeholder="请输入联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文化程度" prop="educationalLevel">
        <el-select v-model="queryParams.educationalLevel" placeholder="请选择文化程度" clearable size="small">
          <el-option
            v-for="dict in educationalLevelOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="政治面貌" prop="politicsStatus">
        <el-select v-model="queryParams.politicsStatus" placeholder="请选择政治面貌" clearable size="small">
          <el-option
            v-for="dict in politicsStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="所属单位" prop="belongUnit">
        <el-input
          v-model="queryParams.belongUnit"
          placeholder="请输入所属单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退伍证件" prop="retiredName">
        <el-input
          v-model="queryParams.retiredName"
          placeholder="请输入退伍证件名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退伍编号" prop="retiredCode">
        <el-input
          v-model="queryParams.retiredCode"
          placeholder="请输入退伍编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['manager:retirefm:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['manager:retirefm:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['manager:retirefm:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['manager:retirefm:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="retirefmList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" :show-overflow-tooltip="true" align="center" prop="name" />
      <el-table-column label="民族" :show-overflow-tooltip="true" align="center" prop="nationality" />
      <el-table-column label="性别" :show-overflow-tooltip="true" align="center" prop="sex" :formatter="sexFormat" />
      <!--      <el-table-column label="出生日期" align="center" prop="birthDate" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.birthDate, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="身份证号" :show-overflow-tooltip="true" align="center" prop="idNumber"  width="190" :formatter="idNumberFormat"/>
      <!-- <el-table-column label="照片" align="center" prop="photo" /> -->
      <!-- <el-table-column label="户籍" :show-overflow-tooltip="true" align="center" prop="addressBirth" /> -->
      <!--      <el-table-column label="家庭住址" align="center" prop="addressLiving" />-->
      <el-table-column label="入伍时间" :show-overflow-tooltip="true" align="center" prop="enterArmyTime" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.enterArmyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="退伍时间" align="center" prop="veteransTime" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.veteransTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="原部队代号" align="center" prop="originalArmyCode" />-->
      <el-table-column label="联系电话" :show-overflow-tooltip="true" align="center" prop="phoneNo" />
      <el-table-column label="文化程度" :show-overflow-tooltip="true" align="center" prop="educationalLevel" :formatter="educationalLevelFormat" />
      <!--      <el-table-column label="婚姻状况 " align="center" prop="marryType" :formatter="marryTypeFormat" />-->
      <el-table-column label="政治面貌" :show-overflow-tooltip="true" align="center" prop="politicsStatus" :formatter="politicsStatusFormat" />
      <!--      <el-table-column label="所属单位" align="center" prop="belongUnit" />-->
      <!--      <el-table-column label="退伍证件名称" align="center" prop="retiredName" />-->
      <!--      <el-table-column label="退伍编号" align="center" prop="retiredCode" />-->
      <!--      <el-table-column label="档案编号" align="center" prop="archiveCode" />-->
      <!--      <el-table-column label="是否悬挂光荣牌" align="center" prop="hangHonourCard" :formatter="hangHonourCardFormat" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['manager:retirefm:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-tickets"
            @click="handleDetails(scope.row)"
            v-hasPermi="['manager:retirefm:remove']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['manager:retirefm:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

<!-- 添加或修改退役军人对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row :gutter="20" >
          <el-col :span="12" >
            <el-form-item label="姓名" prop="name">
              <el-input class="formWidth" v-model="form.name" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item label="民族" prop="nationality">
              <el-input class="formWidth" v-model="form.nationality" placeholder="请输入民族" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" >
          <el-col :span="12" >
            <el-form-item label="性别" prop="sex">
              <el-select v-model="form.sex" placeholder="请选择性别" class="formWidth">
                <el-option
                  v-for="dict in sexOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item label="出生日期" prop="birthDate">
              <el-date-picker clearable size="small"
                              v-model="form.birthDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              class="formWidth"
                              placeholder="选择出生日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" >
          <el-col :span="12" >
            <el-form-item label="身份证号" prop="idNumber">
              <el-input class="formWidth" v-model="form.idNumber" placeholder="请输入身份证号" />
            </el-form-item>
          </el-col>

          <el-col :span="12" >
            <el-form-item label="部队代号" prop="originalArmyCode">
              <el-input class="formWidth" v-model="form.originalArmyCode" placeholder="请输入原部队代号" />
            </el-form-item>
          </el-col>


        </el-row>
        <el-row :gutter="20" >
          <el-col :span="12" >
            <el-form-item label="户籍所在地" prop="addressBirthId">
            <el-cascader
              v-model="form.addressBirthId"
              :options="options"
              :props="propList"
              @change="handleChange"></el-cascader>
              </el-form-item>
          </el-col>

          <el-col :span="12" >
            <el-form-item label="户籍详细地址" prop="addressBirth">
              <el-input class="formWidth" v-model="form.addressBirth" placeholder="请输入户籍详细地址" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" >
          <el-col :span="12" >
            <el-form-item label="现居地" prop="addressLivingId">
            <el-cascader
              v-model="form.addressLivingId"
              :options="options"
              :props="propList"
              @change="handleChange"></el-cascader>
              </el-form-item>
          </el-col>

          <el-col :span="12" >
            <el-form-item label="现居地详细信息" prop="addressLiving">
              <el-input class="formWidth" v-model="form.addressLiving" placeholder="现居地详细信息" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" >
          <el-col :span="12" >
            <el-form-item label="入伍时间" prop="enterArmyTime">
              <el-date-picker clearable size="small"
                              v-model="form.enterArmyTime"
                              type="date"
                              class="formWidth"
                              value-format="yyyy-MM-dd"
                              placeholder="选择入伍时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item label="退伍时间" prop="veteransTime">
              <el-date-picker clearable size="small"
                              v-model="form.veteransTime"
                              type="date"
                              class="formWidth"
                              value-format="yyyy-MM-dd"
                              placeholder="选择退伍时间">
              </el-date-picker>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row :gutter="20" >
          <el-col :span="12" >
            <el-form-item label="联系电话" prop="phoneNo">
              <el-input class="formWidth" v-model="form.phoneNo" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item label="文化程度" prop="educationalLevel">
              <el-select v-model="form.educationalLevel" placeholder="请选择文化程度" class="formWidth">
                <el-option
                  v-for="dict in educationalLevelOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" >
          <el-col :span="12" >
            <el-form-item label="婚姻状况 " prop="marryType">
              <el-select v-model="form.marryType" placeholder="请选择婚姻状况 " class="formWidth">
                <el-option
                  v-for="dict in marryTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item label="政治面貌" prop="politicsStatus">
              <el-select v-model="form.politicsStatus" placeholder="请选择政治面貌" class="formWidth">
                <el-option
                  v-for="dict in politicsStatusOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
       <!---后加---->
        <el-row :gutter="20">
          <el-col :span="12" >
            <el-form-item label="所属单位" prop="belongUnit">
              <el-input v-model="form.belongUnit" placeholder="请输入所属单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item label="退伍证件名称" prop="retiredName">
              <el-input v-model="form.retiredName" placeholder="请输入退伍证件名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12" >
            <el-form-item label="退伍编号" prop="retiredCode">
              <el-input v-model="form.retiredCode" placeholder="请输入退伍编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item label="档案编号" prop="archiveCode">
              <el-input v-model="form.archiveCode" placeholder="请输入档案编号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" >
          <!-- <el-col :span="12" >
            <el-form-item label="原职级" prop="originalRank">
              <el-input v-model="form.originalRank" placeholder="请输入原职级" />
            </el-form-item>
          </el-col> -->
          <el-col :span="12" >
            <el-form-item label="原职级" prop="originalRank">
            <el-cascader
              v-model="form.originalRank"
              :options="rank_options"
              :props="rank_propList"
              @change="handleChange"></el-cascader>
              </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item label="是否悬挂光荣牌">
              <el-radio-group v-model="form.hangHonourCard" class="formWidth">
                <el-radio
                  v-for="dict in hangHonourCardOptions"
                  :key="dict.dictValue"
                  :label="parseInt(dict.dictValue)"
                >{{dict.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <!---后加---->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 基本信息详情 baseInfo -->
    <el-dialog title="详情" :visible.sync="openDetails" width="900px" append-to-body>
      <BaseInfo v-bind:rowInfo="allInfo"></BaseInfo>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="openDetails = !openDetails">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listRetirefm, getRetirefm, delRetirefm, addRetirefm, updateRetirefm, exportRetirefm,cityTree,rankTree }from "@/api/arrangement/arrangement_retirefm";

export default {
  name: "Retirefm",
  data() {
    const  validatorIdNumber = (rule,value,callback)=>{
      let reg =/(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$)/;
      if(!reg.test(value)){
        callback(new Error('请输入正确的身份证号'))
      }else{
        callback()
      }
    }
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 退役军人表格数据
      retirefmList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 性别 1：男性 2：女性字典
      sexOptions: [],
      // 文化程度:1博士、2硕士、3大学本科、4专科、5中专、6高中、7初中及以下字典
      educationalLevelOptions: [],
      // 婚姻状况 1未婚、2已婚、3、离婚、4丧偶字典
      marryTypeOptions: [],
      // 政治面貌字典
      politicsStatusOptions: [],
      // 是否悬挂光荣牌
// 1：是
// 0：否字典
      hangHonourCardOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        nationality: null,
        birthDate: null,
        idNumber: null,
        enterArmyTime: null,
        veteransTime: null,
        phoneNo: null,
        educationalLevel: null,
        politicsStatus: null,
        belongUnit: null,
        retiredName: null,
        retiredCode: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        nationality: [
          { required: true, message: "民族不能为空", trigger: "blur" }
        ],
        sex: [
          { required: true, message: "性别不能为空", trigger: "change" }
        ],
        birthDate: [
          { required: true, message: "出生日期不能为空", trigger: "blur" }
        ],
        idNumber: [
          { required: true, message: "身份证号不能为空", trigger: "blur" },
          {
            validator:validatorIdNumber,
            trigger:"blur"
          }
        ],
        addressBirthId: [
          { required: true, message: "户籍所在地不能为空", trigger: "blur" }
        ],
        addressLivingId: [
          { required: true, message: "现居地不能为空", trigger: "blur" }
        ],
        enterArmyTime: [
          { required: true, message: "入伍时间不能为空", trigger: "blur" }
        ],
        veteransTime: [
          { required: true, message: "退伍时间不能为空", trigger: "blur" }
        ],
        originalArmyCode: [
          { required: true, message: "原部队代号不能为空", trigger: "blur" }
        ],
        phoneNo: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        educationalLevel: [
          { required: true, message: "文化程度不能为空", trigger: "change" }
        ],
        marryType: [
          { required: true, message: "婚姻状况 不能为空", trigger: "change" }
        ],
        politicsStatus: [
          { required: true, message: "政治面貌不能为空", trigger: "change" }
        ],
      },
      openDetails:false,
      // 对应table 这一行的数据
      allInfo:"",
      options:[],
      propList:{
        expandTrigger:"hover",
        value:"id",
        label:"cityName",
        children:"cityChildren"
      },
      rank_options:[],
      rank_propList:{
        expandTrigger:"hover",
        value:"id",
        label:"rank",
        children:"childrenList"
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_user_sex").then(response => {
      this.sexOptions = response.data;
    });
    this.getDicts("degree_of_education").then(response => {
      this.educationalLevelOptions = response.data;
    });
    this.getDicts("marry_type").then(response => {
      this.marryTypeOptions = response.data;
    });
    this.getDicts("political_status").then(response => {
      this.politicsStatusOptions = response.data;
    });
    this.getDicts("yes_or_no").then(response => {
      this.hangHonourCardOptions = response.data;
    });
    this.cityTree();
    this.rankTree();
  },
  methods: {
    // 省市区三级联动
    cityTree(){
      cityTree().then(response =>{
        console.log("city",response)
        this.options = response.data;
      });
    },
    // 原职级联动
    rankTree(){
      rankTree().then(response =>{
        console.log("rank",response)
        this.rank_options = response.data;
      });
    },
    handleChange(value) {
        console.log(value);
      },
    // 查看详情
    handleDetails(rowInfo){
      this.openDetails = true;

      // console.log(JSON.stringify(rowInfo))
      this.allInfo = rowInfo;

    },
    /** 查询退役军人列表 */
    getList() {
      this.loading = true;
      listRetirefm(this.queryParams).then(response => {
        this.retirefmList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 性别 1：男性 2：女性字典翻译
    sexFormat(row, column) {
      return this.selectDictLabel(this.sexOptions, row.sex);
    },
    // 文化程度:1博士、2硕士、3大学本科、4专科、5中专、6高中、7初中及以下字典翻译
    educationalLevelFormat(row, column) {
      return this.selectDictLabel(this.educationalLevelOptions, row.educationalLevel);
    },
    // 婚姻状况 1未婚、2已婚、3、离婚、4丧偶字典翻译
    marryTypeFormat(row, column) {
      return this.selectDictLabel(this.marryTypeOptions, row.marryType);
    },
    // 政治面貌字典翻译
    politicsStatusFormat(row, column) {
      return this.selectDictLabel(this.politicsStatusOptions, row.politicsStatus);
    },
    // 身份证号格式化
    idNumberFormat(row,column){

      return row.idNumber.replace(/^(.{6})(?:\w+)(.{4})$/, "\$1********\$2")
    },
    // 是否悬挂光荣牌
// 1：是
// 0：否字典翻译
    hangHonourCardFormat(row, column) {
      return this.selectDictLabel(this.hangHonourCardOptions, row.hangHonourCard);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        nationality: null,
        sex: null,
        birthDate: null,
        idNumber: null,
        photo: null,
        addressBirth: null,
        addressLiving: null,
        enterArmyTime: null,
        veteransTime: null,
        originalArmyCode: null,
        phoneNo: null,
        educationalLevel: null,
        marryType: null,
        politicsStatus: null,
        belongUnit: null,
        retiredName: null,
        retiredCode: null,
        archiveCode: null,
        originalRank: null,
        hangHonourCard: 0
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加退役军人";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRetirefm(id).then(response => {
        this.form = response.data;
        var addressBirthId = response.data.addressBirthId;
        let birthIdStr = addressBirthId ? addressBirthId.split(',') : null;
        let birthIdArr = birthIdStr ?birthIdStr.map(item => {
          return Number(item)
        }): null;
        this.$set(this.form , 'addressBirthId',birthIdArr)

        var addressLivingId = response.data.addressLivingId;
        let livingIdStr = addressLivingId ? addressLivingId.split(',') : null;
        let livingIdArr = livingIdStr ? livingIdStr.map(item => {
          return Number(item)
        }) : null;
        this.$set(this.form , 'addressLivingId',livingIdArr)

        var originalRank = response.data.originalRank;
      let originalRankStr = originalRank ? originalRank.split(',') : null;
      let originalRankArr = originalRankStr ? originalRankStr.map(item => {
        return Number(item)
      }) : null;
      this.$set(this.form , 'originalRank',originalRankArr)
        this.open = true;
        this.title = "修改退役军人";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.form.addressBirthId = this.form.addressBirthId ? this.form.addressBirthId.join(",") : null;
      this.form.addressLivingId = this.form.addressLivingId ? this.form.addressLivingId.join(",") : null;
      this.form.originalRank = this.form.originalRank ? this.form.originalRank.join(",") : null;
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRetirefm(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRetirefm(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除该项数据?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delRetirefm(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有退役军人数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportRetirefm(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
